package acmCoder;

import java.io.BufferedInputStream;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

/**
 * 你有一个大小为𝑆的𝐽𝑎𝑏𝑏𝑦，每次你可以从你已有的𝐽𝑎𝑏𝑏𝑦中选择一个大小不为1的𝐽𝑎𝑏𝑏𝑦，设他的大小为𝑄，
 * 然后把它分裂成𝑎和𝑄−𝑎，其中1≤𝑎<𝑄，这样你获得的收益是𝑎∗(𝑄−𝑎)给定𝑆，𝑀，求最少分裂几次才能得到至少𝑀的收益
 * Created by shuowu on 2017/11/3.
 */
public class Split {

    public static void main(String[] args){
//        Split object = new Split();
//        object.getRes();
//        String inputPath = "\"wei   bo.mp4\"";
//        String cmd = "ffmpeg -i " + inputPath + " -s 0:0 -t 10 -c:copy out.mp4";
//        String[] cmds = cmd.split("\"?(?=\"[^\\s]+\")");
//        //(?!")\s(?=")
//        //(?!"[^\s])\s(?![^\s]+")
//        for (int i = 0; i < cmds.length; i++) {
//            System.out.println(cmds[i]);
//        }


        String cmd = "ffmpeg -y -ss 0.0 -t 60.0 -i \"/storage/emulated/0/qqbrowser/视频/weibo mpeg4.mp4\" -r 30 -g 30 -filter:v crop=640:640:0:0 -c:v libx264 -threads 8 -preset ultrafast -tune fastdecode -crf 24 -s 720x720 -ar 44100 -ac 1 /storage/emulated/0/Android/data/com.sohu.vtell/files/Draft/video_2096390108.mp4";
        String[] temp = cmd.split("\"");
        System.out.println("ffmpeg" +  "front" + temp[0]);
        String[] front = temp[0].trim().split("\\s+");
        System.out.println("ffmpeg" +  "back" + temp[2]);
        String[] back = temp[2].trim().split("\\s+");
        String[] cmds = new String[front.length + 1 + back.length];
        for (int i = 0; i < front.length; i++) {
            cmds[i] = front[i];
        }
        cmds[front.length] = "\"/storage/emulated/0/qqbrowser/视频/weibo mpeg4.mp4\"";
        for (int i = 0; i < back.length; i++) {
            cmds[i + front.length + 1] = back[i];
        }
        for (int i = 0; i < front.length; i++) {
            System.out.println("ffmpeg front" + front[i]);
        }
        for (int i = 0; i < back.length; i++) {
            System.out.println("ffmpeg back" + back[i]);
        }
        for (int i = 0; i < cmds.length; i++) {
            System.out.println("ffmpeg" + cmds[i]);
        }
    }

    public void getRes(){
        Scanner scanner = new Scanner(new BufferedInputStream(System.in));
        Comparator<Integer> cmp;
        cmp = new Comparator<Integer>() {
            public int compare(Integer e1, Integer e2) {
                return e2 - e1;
            }
        };
        while(scanner.hasNext()){
            PriorityQueue<Integer> treeSet = new PriorityQueue<>(16, cmp);
            int initial = scanner.nextInt();
            int exceptedValue = scanner.nextInt();
            treeSet.add(initial);
            int res = 0;
            boolean canGetRes = true;
            int count = 0;
            while(res < exceptedValue){
                int cur = treeSet.poll();
                //System.out.println(cur);
                if(cur <= 1){
                    canGetRes = false;
                    break;
                }
                count++;
                int middle1 = (cur) >> 1;
                int middle2 = (cur + 1) >> 1;
                res += middle1 * middle2;
                treeSet.add(middle2);
                treeSet.add(middle1);
            }
            if(canGetRes){
                System.out.println(count);
            } else {
                System.out.println(-1);
            }
        }
        scanner.close();
    }
}
